package com.cjkj.system.controller;

import com.cjkj.common.core.utils.poi.ExcelUtil;
import com.cjkj.common.core.web.controller.BaseController;
import com.cjkj.common.core.web.domain.AjaxResult;
import com.cjkj.common.core.web.page.TableDataInfo;
import com.cjkj.common.log.annotation.Log;
import com.cjkj.common.log.enums.BusinessType;
import com.cjkj.common.security.annotation.InnerAuth;
import com.cjkj.common.security.annotation.RequiresPermissions;
import com.cjkj.system.api.domain.THospitalUserOperLog;
import com.cjkj.system.service.ITHospitalUserOperLogService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录
 */
@RestController
@RequestMapping("/operlog")
public class HospitalUserOperlogController extends BaseController
{
    @Resource
    private ITHospitalUserOperLogService operLogService;

    @RequiresPermissions("system:operlog:list")
    @GetMapping("/list")
    public TableDataInfo list(THospitalUserOperLog operLog)
    {
        startPage();
        List<THospitalUserOperLog> list = operLogService.selectTHospitalUserOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:operlog:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, THospitalUserOperLog operLog)
    {
        List<THospitalUserOperLog> list = operLogService.selectTHospitalUserOperLogList(operLog);
        ExcelUtil<THospitalUserOperLog> util = new ExcelUtil<THospitalUserOperLog>(THospitalUserOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @RequiresPermissions("system:operlog:remove")
    @DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(operLogService.deleteTHospitalUserOperLogByOperIds(operIds));
    }

    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody THospitalUserOperLog operLog)
    {
        return toAjax(operLogService.insertTHospitalUserOperLog(operLog));
    }
}
